﻿using B.S.Data.MES.API.Applications.WorkOrderManagement.Commands;
using B.S.Domain.基础数据.客户管理;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;

namespace B.S.Data.MES.API.Applications.WorkOrderManagement.CommandHandlers
{
    public class ShowCustomerCommandHandler : IRequestHandler<ShowCustomerCommand, APIRequst<List<client>>>
    {
        private readonly IBaseRepository<client> _clientRepository;
        public ShowCustomerCommandHandler(IBaseRepository<client> clientRepository)
        {
            _clientRepository = clientRepository;
        }
        public Task<APIRequst<List<client>>> Handle(ShowCustomerCommand request, CancellationToken cancellationToken)
        {
            var code = _clientRepository.GetAll();
            if(code==null)
            {
                return Task.FromResult(new APIRequst<List<client>>
                {
                    Code=RequstCode.失败,
                    Msg=RequstCode.失败.ToString()

                });
            }
            return Task.FromResult(new APIRequst<List<client>>
            {
                Data = code.ToList(),
                Code = RequstCode.成功,
                Msg = RequstCode.成功.ToString()
            });
        }
    }
}
